#include "stdafx.h"
#include "capicon.h"
#include "dialogs.h"

CMakeCallDialog::CMakeCallDialog( const std::string& sCalledNumber, int nBChannel, bool bPreferred ) :
    CDialog( CMakeCallDialog::IDD ),
    m_csCalledNumber( sCalledNumber.c_str() ),
    m_nBChannel( nBChannel )
{
    m_PrefExcl = nBChannel > 0 ? bPreferred ? bcPref : bcExcl : bcAny;
    if ( m_nBChannel == 0 )
        m_nBChannel = 1;
    //{{AFX_DATA_INIT(CMakeCallDialog)
    m_nCIP = 1;
    //}}AFX_DATA_INIT
}

void CMakeCallDialog::DoDataExchange( CDataExchange* pDX )
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMakeCallDialog)
    DDX_Control(pDX, IDC_CALLED_TYPE, m_comboType);
    DDX_Control(pDX, IDC_CALLED_PLAN, m_comboPlan);
    DDX_Text(pDX, IDC_CALLED_NUMBER, m_csCalledNumber);
    DDX_Text(pDX, IDC_B_NUMBER, m_nBChannel);
    DDX_Text(pDX, IDC_CIP, m_nCIP);
    //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMakeCallDialog, CDialog)
    //{{AFX_MSG_MAP(CMakeCallDialog)
    ON_BN_CLICKED(IDC_RADIO_B_ANY, OnRadioB)
    ON_BN_CLICKED(IDC_RADIO_B_EXCL, OnRadioB)
    ON_BN_CLICKED(IDC_RADIO_B_PREF, OnRadioB)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CMakeCallDialog::OnInitDialog() 
{
    CDialog::OnInitDialog();

    m_comboType.SetItemData( m_comboType.InsertString( 0, "Unknown" ),                 0 );
    m_comboType.SetItemData( m_comboType.InsertString( 1, "International number" ),    1 );
    m_comboType.SetItemData( m_comboType.InsertString( 2, "National number" ),         2 );
    m_comboType.SetItemData( m_comboType.InsertString( 3, "Network specific number" ), 3 );
    m_comboType.SetItemData( m_comboType.InsertString( 4, "Subscriber number" ),       4 );
    m_comboType.SetItemData( m_comboType.InsertString( 5, "Abbreviated number" ),      6 );
    m_comboType.SetItemData( m_comboType.InsertString( 6, "Reserved" ),                7 );

    m_comboPlan.SetItemData( m_comboPlan.InsertString( 0, "Unknown" ),                          0 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 1, "ISDN/Telephony numbering plan" ),    1 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 2, "Data numbering plan" ),              3 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 3, "Telex numbering plan" ),             4 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 4, "National standard numbering plan" ), 8 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 5, "Private numbering plan" ),           9 );
    m_comboPlan.SetItemData( m_comboPlan.InsertString( 6, "Reserved" ),                      0x0f );

    m_comboType.SetCurSel( 0 );
    m_comboPlan.SetCurSel( 1 );

    RefreshControls();
    return TRUE;
}

void CMakeCallDialog::RefreshControls() 
{
    SendDlgItemMessage( IDC_RADIO_B_ANY,  BM_SETCHECK, m_PrefExcl == bcAny  ? BST_CHECKED : BST_UNCHECKED );
    SendDlgItemMessage( IDC_RADIO_B_PREF, BM_SETCHECK, m_PrefExcl == bcPref ? BST_CHECKED : BST_UNCHECKED );
    SendDlgItemMessage( IDC_RADIO_B_EXCL, BM_SETCHECK, m_PrefExcl == bcExcl ? BST_CHECKED : BST_UNCHECKED );

    SendDlgItemMessage( IDC_B_NUMBER, WM_ENABLE, m_PrefExcl != bcAny );
}

void CMakeCallDialog::OnRadioB() 
{
    m_PrefExcl = SendDlgItemMessage( IDC_RADIO_B_ANY,  BM_GETCHECK ) == BST_CHECKED ? bcAny  :
                 SendDlgItemMessage( IDC_RADIO_B_PREF, BM_GETCHECK ) == BST_CHECKED ? bcPref :
                 bcExcl;

    RefreshControls();
}

void CMakeCallDialog::OnOK() 
{
    m_cNumberType = (unsigned char)m_comboType.GetItemData( m_comboType.GetCurSel() );
    m_cNumberingPlanId = (unsigned char)m_comboPlan.GetItemData( m_comboPlan.GetCurSel() );

    CDialog::OnOK();
}
